package com.bitinstitute.parkapp.quiz;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.bitinstitute.parkapp.R;
import com.bitinstitute.parkapp.helper.Singleton;

public class Frage3Activity extends Activity {

	Button buttonnext;

	Button buttonback;

	RadioGroup radiogroup;

	int id;

	boolean checkedbutton;

	int position;
	
	
	
	/**
	 * Called when the activity is first created. 
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.frage3);
		Singleton.getInstance().fillArrayListKorrekt();

		buttonnext = (Button) findViewById(R.id.button2);
		radiogroup = (RadioGroup) findViewById(R.id.radioGroup1);
		buttonback = (Button) findViewById(R.id.button3);

		buttonnext.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				id = radiogroup.getCheckedRadioButtonId();
				
				/**
				 * checks which position of the RadioButton is clicked and saves the number in the Integer position 
				 * if there is no RadioButton clicked a Toast is thrown
				 */
					
				if (id != 0) {
					if (id == R.id.radio0) {
						position = 1;
					}
					if (id == R.id.radio1) {
						position = 2;
					}
					if (id == R.id.radio2) {
						position = 3;
					}

					Singleton.getInstance().fillErgebnisse(position, 2);

					Intent in = new Intent(Frage3Activity.this,
							Frage4Activity.class);

					startActivity(in);
					finish();

				} else {

					Toast toast = Toast.makeText(getBaseContext(),
							"Bitte speichern Sie eine Antwort",
							Toast.LENGTH_LONG);
					toast.show();

				}

			}
		});

		buttonback.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				Intent in = new Intent(Frage3Activity.this,
						Frage2Activity.class);

				startActivity(in);
				finish();

			}
		});

	}

}
